package com.cf.studiomanage.service.impl;

import com.cf.studiomanage.entity.Activity;
import com.cf.studiomanage.entity.ActivityRegistration;
import com.cf.studiomanage.mapper.ActivityMapper;
import com.cf.studiomanage.mapper.ActivityRegistrationMapper;
import com.cf.studiomanage.service.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ActivityServiceImpl implements ActivityService {

    @Autowired
    private ActivityMapper activityMapper;
    @Autowired
    private ActivityRegistrationMapper regMapper;

    public boolean create(Activity activity) {
        return activityMapper.createActivity(activity) > 0;
    }

    public boolean update(Activity activity) {
        return activityMapper.updateActivity(activity) > 0;
    }

    public boolean delete(Long id) {
        return activityMapper.deleteActivity(id) > 0;
    }

    public List<Activity> list() {
        return activityMapper.getAllActivities();
    }

    public Activity getById(Long id) {
        return activityMapper.getById(id);
    }

    public boolean register(Long userId, Long activityId) {
        ActivityRegistration reg = new ActivityRegistration();
        reg.setUserId(userId);
        reg.setActivityId(activityId);
        return regMapper.register(reg) > 0;
    }

    public boolean requestLeave(Long userId, Long activityId, String reason) {
        return regMapper.requestLeave(userId, activityId, reason) > 0;
    }

    public boolean signIn(Long userId, Long activityId, String signCode) {
        return regMapper.signIn(userId, activityId, signCode) > 0;
    }

    public List<ActivityRegistration> getRegistrations(Long activityId) {
        return regMapper.getRegistrationsByActivity(activityId);
    }
}
